package com.atguigu.gmall.user.rest;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.common.util.IpUtil;
import com.atguigu.gmall.user.service.UserInfoService;
import com.atguigu.gmall.user.vo.LoginResultVo;
import com.atguigu.gmall.user.vo.LoginVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author:lyd
 * @Date:2023/8/29 17:07
 * @Version:1.0
 * @Description
 **/
@RestController
@RequestMapping("/api/user/passport")
public class LoginRestController {

    @Autowired
    private UserInfoService userInfoService;

    @PostMapping("/login")
    public Result userLogin(@RequestBody LoginVo loginVo, HttpServletRequest request) {
        String ip = IpUtil.getIpAddress(request);
        LoginResultVo result = userInfoService.userLogin(loginVo,ip);
        return Result.ok(result);
    }

    @GetMapping("/logout")
    public Result logout(@RequestHeader("token") String token) {
        userInfoService.logout(token);
        return Result.ok();
    }

//    @GetMapping("/")

}
